<template>
  <div class="box">
    <div class="box_div">
      <div class="box_top">
        <div class="top_left">
          <el-button type="primary" icon="el-icon-user" circle></el-button>
          <span style="margin-left: 10px;">智慧物业管理系统</span>
        </div>
        <div class="top_right" @click="outLogin">退出登录</div>
      </div>
      <!-- 小区列表展示 -->
      <div class="box_button">
        <div class="content">
          <div class="div" v-for="(item,index) in tableData">
            <div class="div_top">
              <el-image
              style="width: 100%; height: 100%"
              :src="item.villageImage.split(',')[0]"></el-image>
            </div>
            <div class="div_div">{{item.villageName}}</div>
            <div class="div_p">{{item.villageAddress}}</div>
            <div class="div_botton">
              <el-button type="text" @click="dumpManage(item)" class="botton">管理</el-button>
              <el-button type="text" @click="dumpVillageUpdate(item)" class="botton">编辑</el-button>
              <el-button type="text" @click="delVillageInfo(item.id)" class="botton" style="color: red;border-right: none;">删除</el-button>
            </div>
          </div>
          <div class="add" @click="toVillageAdd">
            <div class="icno"><i class="el-icon-plus"></i></div>
            <div class="p">新建小区</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SmartPropertyVueVillage',

  data() {
    return {
      tableData: []
    }
  },

  mounted() {
    this.queryVillageInfo()
  },

  methods: {
    outLogin() { // 退出登录
      this.$confirm('确定退出系统吗?', '退出系统确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        window.localStorage.clear()
        this.$router.push('/')
        this.MyMessage('退出成功!', 'success')
      })
    },
    queryVillageInfo() { // 小区列表展示
      this.$axios.get('/memberCjq/village/queryVillageInfo').then(res => {
        if (res.status === 200) {
          this.tableData = res.data.obj
        }
      })
    },
    delVillageInfo(obj) { // 删除小区信息
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete('/memberCjq/village/delVillageInfo', {
          params: {
            id: obj
          }
        }).then(res => {
          if (res.data.code === 200) {
            this.MyMessage('删除成功!', 'success')
            this.queryVillageInfo()
            this.insertLog('小区信息删除')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    dumpManage(obj) { // 跳转小区管理页面
      this.$router.push({path:'/home'})
      window.sessionStorage.setItem('vid', obj.id)
      window.sessionStorage.setItem('villageName', obj.villageName)
    },
    dumpVillageUpdate(obj) { // 跳转小区编辑页面
      this.$router.push({path:'/villageUpdate', query: {villageForm: obj}})
    },
    toVillageAdd() { // 跳转新建小区页面
      this.$router.push('/villageAdd')
    },
    MyMessage (msg, type) {
      this.$notify({
        showClose: true,
        message: msg,
        type: type
      })
    }
  }
}
</script>

<style scoped>
.box{
  width: 100%;
  height: 100vh;
  cursor: pointer;
  background: #F0F2F5;
  font-family: '微软雅黑';
}
.box_div{
  width: 100%;
  height: 100%;
  margin: 0 auto;
}
.box_top{
  width: 100%;
  height: 65px;
  background: #FFF;
}
.box_button{
  width: 100%;
}
.content{
  width: 1200px;
  height: 100%;
  margin: 0 auto;
}
.div{
  width: 270px;
  height: 290px;
  float: left;
  margin-top: 20px;
  margin-left: 22px;
  background: #FFF;
  border: 1px solid #E9E9E9;
}
.div:hover{
  box-shadow: 0px 2px 14px #CED0D2;
}
.div:hover .div_div{
  color: #1890FF;
}
.div_div{
  font-size: 16px;
  font-weight: 500;
  margin: 20px 0 0 20px;
}
.div_top{
  width: 100%;
  background: #F1F5FB;
  height: 150px;
}
.div_botton{
  width: 100%;
  height: 55px;
  line-height: 55px;
  border-top: 1px solid #F9F9F9;
  margin-top: 15px;
}
.botton{
  width: 83px;
  height: 45px;
  border-right: 1px solid #F2F2F2;
}
.add{
  width: 270px;
  height: 290px;
  float: left;
  margin-top: 20px;
  margin-left: 22px;
  background: #FFF;
  border: 1px dashed #E9E9E9;
}
.add:hover{
  border: 1px dashed #1890FF;
}
.add:hover div{
  color: #1890FF;
}
.icno{
  width: 100%;
  height: 28px;
  color: #C0C0C0;
  text-align: center;
  margin-top: 40%;
}
.p{
  width: 100%;
  height: 28px;
  color: #C0C0C0;
  text-align: center;
}
.top_left{
  width: 300px;
  height: 100%;
  line-height: 63px;
  margin-left: 12%;
  font-size: 18px;
  font-weight: 500;
  float: left;
}
.top_right{
  width: 100px;
  height: 100%;
  line-height: 63px;
  text-align: center;
  font-size: 14px;
  float: right;
  color: #333333;
  margin-right: 14%;
}
.top_right:hover{
  color: #1890FF;
}
.div_p{
  width: 230px;
  height: 20px;
  white-space:nowrap;
	text-overflow:ellipsis;
	overflow:hidden;
  font-size: 14px;
  color: #8D8D8D;
  font-weight: 500;
  margin: 10px 0 0 20px;
}
</style>
